import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterdemo/1demo/common/common.dart';
import 'package:flutterdemo/1demo/pages/about_page.dart';
import 'package:flutterdemo/1demo/pages/black_home_page.dart';
import 'package:flutterdemo/1demo/pages/publish_page.dart';
import 'package:flutterdemo/1demo/pages/setting_page.dart';

class LeftDrawer extends StatelessWidget {
  final String headImagePath;
  final List<String> menuTitle;
  final List menuIcons;

  LeftDrawer({Key key, @required this.headImagePath, @required this.menuTitle, @required this.menuIcons})
      : assert(headImagePath != null),
        assert(menuTitle != null),
        assert(menuIcons != null),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer(
      elevation: 10,
      child: ListView.separated(
          // 解决状态栏问题
          padding: EdgeInsets.all(0),
          itemBuilder: (context, index) {
            if (index == 0) {
              return Image.asset(
                headImagePath,
                height: 230,
                width: get0_7screenWidth(context),
                fit: BoxFit.cover,
              );
            } else {
              return ListTile(
                leading: Icon(menuIcons[index - 1]),
                title: Text(menuTitle[index - 1]),
                trailing: Icon(Icons.arrow_forward),
                onTap: () {
                  switch (index - 1) {
                    case 0:
                      _navigate(context, PublishPage());
                      break;
                    case 1:
                      _navigate(context, BlackHomePage());
                      break;
                    case 2:
                      _navigate(context, AboutPage());
                      break;
                    case 3:
                      _navigate(context, SettingPage());
                      break;
                  }
                },
              );
            }
          },
          separatorBuilder: (context, index) {
            if (index == 0) {
              return Divider(
                height: 0,
              );
            } else {
              return Divider(
                height: 1,
              );
            }
          },
          itemCount: menuTitle.length + 1),
    );
  }

  void _navigate(BuildContext context, Widget page) {
    Navigator.push(context, MaterialPageRoute(builder: (context) => page));
  }
}
